{
 "cells": [
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "w# 掌握numpy的数据类型，练习数组和数的运算，数组和数组的运算，理解数组的轴",
   "id": "e7251fd65a671ca4"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "import numpy as np",
   "id": "98de422c7204494f"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "initial_id",
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# 数组和数之间的运算是广播\n",
    "array_1 = np.arange(24).reshape(4, 6)\n",
    "array_2 = np.arange(100, 124).reshape(4, 6)\n",
    "print(array_1 + 10)\n",
    "# 数组和数组之间的运算是同形状\n",
    "print(array_1 + array_2)\n",
    "print(array_1 * array_2)\n",
    "#数组和数组之间的运算是有一个轴相同\n",
    "array_3 = np.arange(6).reshape(1, 6)\n",
    "array_4 = np.arange(4).reshape(4, 1)\n",
    "print('-' * 50)\n",
    "print(array_1)\n",
    "print(array_3)\n",
    "print(array_1 + array_3)  # (4,6)和(1,6)轴1相同，那就是轴1上的所有元素按照轴1的顺序广播\n",
    "print('-' * 50)\n",
    "print(array_1)\n",
    "print(array_4)\n",
    "# print(array_1+array_4)    # (4,6)和(4,1)轴0相同，那就把轴0的元素全部按顺序广播到轴0上"
   ]
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": [
    "array_1 = np.arange(1, 7).reshape((2, 3))\n",
    "print(array_1)\n",
    "# 按照轴0求和\n",
    "print(np.sum(array_1, axis=0))\n",
    "# 按照轴1求和\n",
    "print(np.sum(array_1, axis=1))\n",
    "array_2 = np.arange(24).reshape(2, 3, 4)\n",
    "print(array_2)\n",
    "a = np.sum(array_2, axis=0)\n",
    "b = np.sum(array_2, axis=1)\n",
    "c = np.sum(array_2, axis=2)\n",
    "print(np.sum(array_2, axis=0).shape)\n",
    "print(np.sum(array_2, axis=1).shape)\n",
    "print(np.sum(array_2, axis=2).shape)"
   ],
   "id": "29dd29bce8de54b1"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
